package org.dicr.mng.exc;

import java.util.*;

/**
 * Command execution exception.
 * 
 * @author <A href='http://dicr.org'>Igor A Tarasov</A>\
 * @version 060515
 */
public class CommandException extends ManageException {
	private static final long serialVersionUID = 1L;

	/**
	 * Constructor
	 * 
	 * @param message
	 */
	public CommandException(String message) {
		super(message);
	}

	/**
	 * Constructor
	 * 
	 * @param message
	 * @param cause
	 */
	public CommandException(String message, Throwable cause) {
		super(message, cause);
	}

	/**
	 * Constructor
	 * 
	 * @param cause
	 */
	public CommandException(Throwable cause) {
		super(cause);
	}

	/**
	 * Constructor
	 * 
	 * @param command
	 * @param errorMessage
	 */
	public CommandException(List<String> command, String errorMessage) {
		super(command2string(command) + ":" + errorMessage);
	}

	/**
	 * Constructor
	 * 
	 * @param command
	 * @param cause
	 */
	public CommandException(List<String> command, Throwable cause) {
		super(command2string(command), cause);
	}

	/**
	 * Translate command to stricg
	 * 
	 * @param command
	 * @return command stricg
	 */
	protected static String command2string(List<String> command) {
		if (command == null) return null;
		StringBuilder sb = new StringBuilder();
		for (String cp : command)
			sb.append(cp).append(' ');
		return sb.toString();
	}
}
